package com.boot.unity.api.wx.service;

import com.alibaba.fastjson.JSONObject;
import okhttp3.*;
import org.springframework.stereotype.Service;

@Service
public class CommonUtilUrlService {
    public String post(String url,String json) throws Exception{
        OkHttpClient client = new OkHttpClient().newBuilder().build();
        MediaType mediaType = MediaType.parse("application/json");
        RequestBody body = RequestBody.create(mediaType, json);
        Request request = new Request.Builder()
                .url(url).method("POST", body)
                .addHeader("Content-Type", "application/json")
                .build();
        Response response = client.newCall(request).execute();
        String dataJson = response.body().string();
        JSONObject jsonData = JSONObject.parseObject(dataJson);
        return jsonData.getString("data");
    }
}
